<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;
class LoginController extends Controller
{
    public function getIndex(){
        return view('home/login/index');
    }
    public function postLogin(Request $request){
    	if(empty($request -> input('name'))){
    		return back() -> withInput() -> with('error','用户名必填');
    	}
    	if(empty($request -> input('password'))){
    		return back() -> withInput() -> with('error','密码必填');
    	}
    	$a = $request -> only('name','password');
    	$data = DB::table('shop_users') -> where('username',$a['name']) -> orwhere('email',$a['name']) -> where('status',2) -> first();
    	if(empty($data)){
    		return back() -> withInput() -> with('error','该用户不存在');
    	}
    	if(!(Hash::check($a['password'],$data['password']))){
    		return back() -> withInput() -> with('error','用户名或密码错误');
    	}else{
    		session(['data'=>$data]);
    		// dd(session('data'));
    		return redirect('/home/sy') -> with('success','登录成功');
    	}
    }
}
